var express = require('express');
var path = require('path');
var proxyMiddleware = require ('http-proxy-middleware');

var app = express();

var javaHOST = 'http://127.0.0.1:5555';          // 你们的项目地址
var projectName = '/api';                        // 你们的项目名称

app.use(express.static(path.join(__dirname, 'public')));

/***
 * 调试后台 实际测试接口
 **/
app.use(projectName, function (req, res, next) {
    console.log('存在请求转发！');
    next();
});

app.use(proxyMiddleware(projectName, {
    target: javaHOST + projectName,
    // pathRewrite: { ['^' + projectName ] : javaProjectName},
    secure: false,
    changeOrigin: true
}));

app.use(projectName, function (req, res, next) {
    console.log('请求转发结束！');
    next();
});
module.exports = app;
